import _ from 'lodash'

export default class BaseModel {
  static type = 'model';

  constructor(data = null) {
    if (data !== null) {
      this.model(data);
    }
  }

  model(data) {
    for (let property of _.keys(this)) {
      if (data.hasOwnProperty(property)) {
        if (this[property] instanceof BaseModel) {
          this[property].model(data[property])
        } else {
          this[property] = data[property];
        }
      }
    }
  }

}
